
import $ from 'jquery'

import Vue from 'vue'

import VueRouter from 'vue-router'
import router from './router'
Vue.use(VueRouter)

import VueResource from 'vue-resource'
Vue.use(VueResource)
// vue.http.options.root = '';
// vue.http.options.emulateJSON = true;

import Vuex from 'vuex'
Vue.use(Vuex)

var car = JSON.parse(localStorage.getItem('car') || '[]')

var store = new Vuex.Store({
	state:{
		car: car
	},
	mutations:{
		addToCar(state , goodsinfo) {
			var flag = false;

			state.car.some(item => {
				if(item.id == goodsinfo.id) {
					item.count += parseInt(goodsinfo.count);
					flag = true;
					return true
				}
			});

			if(!flag) {
				state.car.push(goodsinfo)
			}

			localStorage.setItem('car',JSON.stringify(state.car))

		}
	},
	getters:{
		getAllCount(state) {
			var c = 0;
			state.car.forEach(item => {
				c += item.count;
			})
			return c
		}
	}
})


// import Vue from '../node_modules/vue/dist/vue.js'
// import './css/index.css'
// require('style-loader!css-loader!./css/index.css'); 
// require('mint-ui/lib/style.css'); 
import 'mint-ui/lib/style.css'

// 按需导入Mint-UI的组件
// import { Header , Swipe , SwipeItem , Button , Lazyload} from 'mint-ui'
// Vue.component(Header.name,Header)
// Vue.component(Swipe.name, Swipe)
// Vue.component(SwipeItem.name, SwipeItem)
// Vue.component(Button.name, Button)
// Vue.use(Lazyload)
import MintUI from 'mint-ui'
Vue.use(MintUI)

import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
Vue.use(preview)


import app from './App.vue'

// 导入MUI的样式 
import './lib/mui/css/mui.min.css'
import './lib/mui/css/icons-extra.css'
 

var vm = new Vue({
	el:'#app',
	render:c => c(app),
	router,
	store
})
